package LeetCode.month02.day32;

import java.util.*;

public class No2781 {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("aaa");
        list.add("cb");
        System.out.println(longestValidSubstring("cbaaaabc",list));
    }
    public static int longestValidSubstring(String word, List<String> forbidden) {
        Set<String> set = new HashSet<>(forbidden);
        int n = word.length();
        int res = 0;
        int left = 0;
        for (int right = 0; right < n; right++) {
            for (int i = right; i >=left&&i>right-10; i--) {
                if(set.contains(word.substring(i,right+1))){
                    left=i+1;
                    break;
                }
            }
            res = Math.max(res,right-left+1);
        }
        return res;
    }
}
